<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>ztree</title>
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/common/bootstrap/css/bootstrap.min.css"/>
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/common/zTree/css/metroStyle/metroStyle.css"/>
    <script type="text/javascript" src="${pageContext.request.contextPath}/common/js/jquery-2.1.4.min.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/common/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/common/zTree/js/jquery.ztree.all.js"></script>

    <script type="text/javascript">

    	var setting = {
    		view: {
    			selectedMulti: false
    		},
    		check: {
                enable: true,
                chkboxType: { "Y": "", "N": "" }
    		},
    		async: {
				enable: true,
				url:"${pageContext.request.contextPath}/tree/getTreeByPid",
				autoParam:["id", "pid"]
			},
			callback: {
                beforeCheck: function(treeId, treeNode){
                    //var treeObj = $.fn.zTree.getZTreeObj(treeId);
                    //treeObj.cancelSelectedNode();
                    //treeObj.checkAllNodes(false);
                    //var checkedNode = treeObj.getCheckedNodes()[0];
                    //treeObj.selectNode(checkedNode);
                },
                onCheck: function(event, treeId, treeNode){
                    var treeObj = $.fn.zTree.getZTreeObj(treeId);
                    treeObj.cancelSelectedNode();
                    treeObj.checkAllNodes(false);
                    treeObj.checkNode(treeNode, true, true);
                    treeObj.selectNode(treeNode);
                },
                beforeClick: function(treeId, treeNode, clickFlag){

                },
                onClick: function(event, treeId, treeNode){
                    var treeObj = $.fn.zTree.getZTreeObj(treeId);
                    treeObj.cancelSelectedNode();
                    treeObj.checkAllNodes(false);
                    treeObj.checkNode(treeNode, true, true);
                    treeObj.selectNode(treeNode);
                }
			}
    	};

	    $(document).ready(function(){

	    	//ztree init
	    	$.fn.zTree.init($("#tree"), setting);
	    });

    </script>
</head>
<body>
<ul id="tree" class="ztree"></ul>
</body>
</html>
